<?php
include ('config.php');
ob_start();

$tbl_name="klant_new"; // Table name

$confirm_code=md5(uniqid(rand())); //random confirmatie code(md5 ftw!)

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// Define $myusername and $mypassword 
$myname=$_POST['myname']; 
$mypassword=$_POST['mypassword'];
$myemail=$_POST['myemail'];
$myadres=$_POST['myadres'];
$mypostcode=$_POST['mypostcode'];
$mywoonplaats=$_POST['mywoonplaats'];
$mytelefoon=$_POST['mytelefoon'];


// To protect MySQL injection 
$myname = stripslashes($myname);
$mypassword = stripslashes($mypassword);
$myemail = stripslashes($myemail);
$myadres = stripslashes($myadres);
$mypostcode = stripslashes($mypostcode);
$mywoonplaats = stripslashes($mywoonplaats);
$mytelefoon = stripslashes($mytelefoon);
$myname = mysql_real_escape_string($myname);
$mypassword = mysql_real_escape_string($mypassword);
$myemail= mysql_real_escape_string($myemail);
$myadres= mysql_real_escape_string($myadres);
$mypostcode = mysql_real_escape_string($mypostcode);
$mywoonplaats = mysql_real_escape_string($mywoonplaats);
$mytelefoon = mysql_real_escape_string($mytelefoon);

$sql="INSERT INTO `$tbl_name` VALUES ('$confirm_code', '$myname','$myadres','$mywoonplaats','$mypostcode','$mytelefoon','$myemail','$mypassword')";
$result=mysql_query($sql);

if ($result){
	//JAJA, nu gaan we ff mailtje versturen
// send e-mail to ...
$to=$myemail;

// Your subject
$subject="Your confirmation link here";

// From
$header="from: Group 3 productions <info@group3productions>";

// Your message
$message="Your Comfirmation link \r\n";
$message.="Click on this link to activate your account \r\n";
$message.="http://www.group3productions.info/confirmation.php?passkey=$confirm_code";

// send email
$sentmail = mail($to,$subject,$message,$header);

}

// if not found 
else {
echo "Not found your email in our database";
}

// if your email succesfully sent
if($sentmail){
echo "Your Confirmation link Has Been Sent To Your Email Address.";
}
else {
echo "Cannot send Confirmation link to your e-mail address";
}
	


// header("location:index.php");
ob_end_flush();
?>